﻿appRoot.controller('SecurityController', function ($scope, $location, $resource) {
    
    var sResource = $resource('/api/security', {}, { get: { method: 'GET' }, update: { method: 'POST' } });

    $scope.pkiList = [
        { name: 'MD5-RSA-384', id: 128 },
        { name: 'SHA1-RSA-1024', id: 64 }
    ];


    $scope.getSecurityParameter = function () {
        $scope.securityParameter = sResource.get({});
    };

    $scope.updateSecurity = function (parameter) {

        sResource.update(parameter, function success(parameter) {
            $scope.securityParameter.pkiType = parameter.pkiType;
            $scope.securityParameter.publicKeyPath = parameter.publicKeyPath;
            $scope.securityParameter.privateKeyPath = parameter.privateKeyPath;
            $scope.securityParameter.caUrl = parameter.caUrl;
            $scope.securityParameter.raUrl = parameter.raUrl;
            $scope.securityParameter.vaUrl = parameter.vaUrl;

            setTimeout(function () {
                $.Notify({
                    style: {
                        background: 'green',
                        color: 'white'
                    },
                    shadow: true,
                    position: 'bottom-left',
                    caption: 'Data Security',
                    content: "Configuration has been updated succesfully."
                });
            }, 1000);
        }, function error() {
            setTimeout(function () {
                $.Notify({
                    style: {
                        background: 'red',
                        color: 'white'
                    },
                    shadow: true,
                    position: 'bottom-left',
                    caption: 'Data Security',
                    content: "Configuration cannot be updated."
                });
            }, 1000);
        });
    };
});